// development_hand.cc
#include "development_hand.h"

DevelopmentHand::DevelopmentHand() {
  playable_= true;
  memset(new_cards_, 0, sizeof(new_cards_));
  memset(counts_, 0, sizeof(counts_));
  size_ = 0;
}

void DevelopmentHand::StartOfTurn() {
  for (int i = 0; i < kNumDevTypes; i++) {
    size_ += new_cards_[i];
    counts_[i] += new_cards_[i];
    new_cards_[i] = 0;
  }
  playable_ = true;
}

bool DevelopmentHand::HaveCard(int type) {
  return (!IsInvalid(type) && counts_[type] > 0);
}

bool DevelopmentHand::HavePlayableCard(int type) {
  return (HaveCard(type) && (playable_ || type == VICTORY_POINT));
}

int DevelopmentHand::PlayCardOfType(int type) {
  if (!HavePlayableCard(type))
    return INVALID_TYPE;
  counts_[type]--;
  size_--;
  if (type != VICTORY_POINT)
    playable_ = false;
  return type;
}

bool DevelopmentHand::AddCardOfType(int type) {
  if (IsInvalid(type) || counts_[type] + 1 > kMaxNumPerType[type])
    return false;
  if (type == VICTORY_POINT) {
    counts_[type]++;
    size_++;
  }
  else {
    new_cards_[type]++;
  }
  return true;
}


